package com.example.demo.service.impl;

import com.example.demo.dao.UsersDao;
import com.example.demo.entity.Users;
import com.example.demo.service.UsersService;
import com.example.demo.vo.UsersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service //业务逻辑层
public class UsersServiceImpl implements UsersService {

    @Autowired //用于实现依赖注入，可以应用于构造函数、字段、以及配置方法上，以实现自动装配功能。
    private UsersDao usersDao;

    @Override //Java注解，覆盖
    @Transactional //Spring注解，声明事务，确保方法内的数据库操作在一个事务中执行，支持事务回滚
    public int register(Users users){
        int r = usersDao.register(users);
        return r;
    }

    @Override
    public List<UsersVO> findAll(){
        return usersDao.findAll();
    }

    @Override
    public Users findByName(String name){
        return usersDao.findByName(name);
    }

    @Override
    public int deleteById(Integer id){
        return usersDao.deleteById(id);
    }

    @Override
    public int deleteByName(String name){
        int r = usersDao.deleteByName(name);
        return r;
    }

    @Override
    @Transactional
    public int update(Users users){
        int r2 = usersDao.update(users);
        return r2;
    }

    @Override
    public Users findUsers(String username,String pwd) {
        return usersDao.findUsers(username,pwd);
    }

}
